package com.pro.common.api.statics.user.file.storage.service;

import com.pro.common.api.statics.user.file.storage.enums.EnumFileStoragePlatform;
import com.pro.common.api.statics.user.file.storage.model.dto.TempCredentialDTO;
import com.pro.common.api.statics.user.file.storage.model.dto.UploadFIleResultDTO;
import com.pro.framework.api.file.storage.PresignedUrlResponse;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * 通用对象存储接口（AWS S3 / 阿里 OSS / 华为 OBS 风格）
 */
public interface IFileStorageService {

//    EnumFileStoragePlatform getPlatform();
    // ====================== 预签名 ======================

    PresignedUrlResponse generatePresignedUploadUrl(String bucket, String objectKey, long expireSeconds, String contentType);

//    String getBucketName(String bucket);

    PresignedUrlResponse generatePresignedDownloadUrl(String bucket, String objectKey, long expireSeconds);


    // ====================== 上传 ======================

    PresignedUrlResponse generatePresignedUploadUrlWithCallback(String bucket, String objectKey, long expireSeconds, Map<String, String> customVariables);

    UploadFIleResultDTO putObject(String bucket, String objectKey, InputStream inputStream);

    Map<String, String> putObjectsFromUrls(String bucket, String objectKeyPrefix, List<String> sourceUrls);

    default String initiateMultipartUpload(String bucket, String objectKey) {
        return null;
    }

    default String uploadPart(String bucket, String objectKey, String uploadId, int partNumber, InputStream inputStream) {
        return null;
    }

    default String completeMultipartUpload(String bucket, String objectKey, String uploadId, List<String> partETags) {
        return null;
    }

    default boolean abortMultipartUpload(String bucket, String objectKey, String uploadId) {
        return false;
    }


    // ====================== 下载 ======================

    InputStream getObject(String bucket, String objectKey);


    // ====================== 删除 ======================

    boolean deleteObject(String bucket, String objectKey);

    List<String> deleteObjects(String bucket, List<String> objectKeys);


    // ====================== 查询 ======================

    boolean doesObjectExist(String bucket, String objectKey);

    Map<String, Object> getObjectMetadata(String bucket, String objectKey);

    default List<String> listObjects(String bucket, String prefix, String marker, int maxKeys) {
        return List.of();
    }


    // ====================== 拷贝 / 移动 ======================

    default boolean copyObject(String sourceBucket, String sourceKey, String targetBucket, String targetKey) {
        return false;
    }

    default boolean moveObject(String sourceBucket, String sourceKey, String targetBucket, String targetKey) {
        return false;
    }


    // ====================== 桶管理（可选） ======================

    default boolean createBucket(String bucket) {
        return false;
    }

    default boolean deleteBucket(String bucket) {
        return false;
    }

    default boolean doesBucketExist(String bucket) {
        return false;
    }

    String getObjectUrlPublic(String bucket, String objectKey);

    default String getObjectUrl(String bucket, String objectKey, boolean isPublic, long expireSeconds){
        return null;
    }

    Object uploadCallback(Map<String, String> headers, Map<String, Object> paramMap, String body);
    /**
     * 获取临时凭证（STS）
     */
    default TempCredentialDTO getTemporaryCredentials() {
        throw new UnsupportedOperationException("This storage platform does not support STS temporary credentials");
    }

}
